package crack;

import crack.transformer.Class2FileTransformer;
import crack.transformer.CodeRemoverAgent;
import crack.transformer.MultiMethodTransformer;
import crack.transformer.SingleMethodTransformer;
import javassist.ClassPool;
import javassist.CtClass;
import java.lang.instrument.ClassDefinition;
import java.lang.instrument.Instrumentation;

public class FineCrackAgent {
    public static void agentmain(String args, Instrumentation inst) throws Exception {

        Class<?>[] classes = inst.getAllLoadedClasses();
        for (Class<?> clazz : classes) {
            String name = clazz.getName();
            if (name.equals("com.fr.license.selector.EncryptedLicenseSelector")) {
//                System.out.println(name + " 被扫瞄了");
//                inst.addTransformer(new SingleMethodTransformer(name, "decrypt", 1, 2, new byte[]{(byte) 0x2B, (byte) 0xB0}, null), true);
//                inst.retransformClasses(clazz);
//                System.out.println(name + " 替换完成！");
                System.out.println(name + " 被扫瞄了");
                inst.addTransformer(new Class2FileTransformer(name,"decrypt","{return $1;}",true),true);
                inst.retransformClasses(clazz);
                System.out.println(name + " 替换完成！");
            }

            if (name.equals("com.fr.license.security.LicFileRegistry")) {
//                inst.addTransformer(new SingleMethodTransformer(name, "check", 1, 2, new byte[]{4, -84}, null), true);
                inst.addTransformer(new SingleMethodTransformer(name, "check", 1, 2, new byte[]{4, -84}, null), true);
                inst.retransformClasses(clazz);
                System.out.println(name + " 替换完成！");
            }
            if (name.equals("com.fr.license.entity.AbstractLicense")) {
                System.out.println(name + " 被扫瞄了");
                inst.addTransformer(new MultiMethodTransformer(name, "support", 1, 2, new byte[]{4, -84}, null), true);
                inst.retransformClasses(clazz);
                System.out.println(name + " 替换完成！");
            }

            if (name.equals("com.fr.license.security.LicFileCheckerImpl")) {
                inst.addTransformer(new SingleMethodTransformer(name, "check", 1, 2, new byte[]{4, -84}, null), true);
                inst.retransformClasses(clazz);
                System.out.println(name + " 替换完成！");
            }
        }

    }






}
